﻿@model IEnumerable<tutors_clus.Models.news>

@{
    ViewBag.Title = "Danh sách tin tức";
    Layout = "~/Views/Shared/_Layout_Private.cshtml";
}
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.8/jquery-ui.min.js" type="text/javascript"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.8/i18n/jquery-ui-i18n.min.js" type="text/javascript"></script>
<div id="cleft">@Html.Partial("_menu_admin")</div>
<div id="cright">
<h3>Danh sách tin tức</h3>
<table id="result">
    <tr>
        <th>
            @Html.ActionLink("Tiêu đề", "Show_News", new {order = ViewBag.Titles,page = ViewBag.PageNumber})
        </th>
        <th>
            @Html.DisplayNameFor(model => model.image_news)
        </th>
        <th>
            @Html.ActionLink("Ngày tạo", "Show_News", new {order = ViewBag.Date,page = ViewBag.PageNumber})
        </th>
        <th>
            @Html.DisplayNameFor(model => model.writer_new)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.status_new)
        </th>
        <th>Hành động</th>
    </tr>
    <tbody class="sort">
@foreach (var item in Model) {
    <tr rel="@item.id_new">
        <td>
            @Html.DisplayFor(modelItem => item.title_new)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.image_news)
        </td>
        <td>
            @Html.DisplayFor(m => item.create_date_new)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.writer_new)
        </td>
       <td id="@item.id_new">
          
            @if (item.status_new == true)
            {
                @Ajax.ActionLink("tick", "Change_sta_news", new {id = item.id_new}, new AjaxOptions {InsertionMode=InsertionMode.Replace, UpdateTargetId = item.id_new.ToString()},new { @class="true" })
            }
            else
            {
                 @Ajax.ActionLink("tick", "Change_sta_news", new {id = item.id_new}, new AjaxOptions {InsertionMode=InsertionMode.Replace, UpdateTargetId = item.id_new.ToString()},new { @class="false" })
            }
        </td>
        <td>
            @Html.ActionLink("Sửa", "Edit_news", new { id=item.id_new}) |
            @Html.ActionLink("Chi tiết", "Detail_news", new { id=item.id_new}) |
            @Html.ActionLink("Xoá", "Delete_News", new { id = item.id_new }, new { onclick = "return confirm('Bạn có chắc muốn xóa không?');" })
            @*<input type="button" title="Xóa tin tức" value="Xóa" onclick="if (confirm('Bạn có chắc muốn xóa không?')) location.href='@Url.Action("Delete_News", "Admin", new { id = item.id_new })'" />*@
        </td>
    </tr>
}
</tbody>
</table>
</div>
<script>
    $(document).ready(function() {
        currPos1 = "";
        currPos2 = "";
        //var currPos3 = "";

        $(".sort").sortable({
            start: function (event, ui) {
                currPos1 = ui.item.index();
            },
            update: function(event, ui) {
               
                currPos2 = ui.item.index();
                var id_cnnou =ui.item.attr('rel');
                $.ajax({
                    type: "POST",
                    url: '/Admin/UpdatePosition_News',
                    data: 'id_news='+id_cnnou+'&&start='+ currPos1+'&&end='+currPos2

                })
            }

        }); 
    });
</script>  